package com.ld.security.auth.common.sys.service.impl;


import com.ld.security.common.core.util.ReflectionUtil;
import com.ld.security.common.mybatis.base.service.ITreeServiceImpl;
import com.ld.security.auth.common.sys.constant.SysPerConstant;
import com.ld.security.auth.common.sys.entity.SysPerEntity;
import com.ld.security.auth.common.sys.service.ISysPerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysPerServiceImpl  extends ITreeServiceImpl<SysPerEntity>
implements
        ISysPerService {



        @Override
        public int saveTree(List<SysPerEntity> tree) {
            for (SysPerEntity entity : tree) {
                    if(entity.getPerType() == null){
                            List children  = entity.getChildren();
                            if(ReflectionUtil.isNotNull(children)){
                                    if(children.size() == 1){
                                            entity.setPerType(SysPerConstant.perType.view);
                                    }else{
                                            entity.setPerType(SysPerConstant.perType.menu);
                                    }
                            }else{
                                    entity.setPerType(SysPerConstant.perType.view);

                            }
                    }
                    if(entity.getHidden() == null){
                            entity.setHidden(false);
                    }
            }
                return super.saveTree(tree);
        }
}
